"""
产品价格控制器
"""
from typing import List
from fastapi import APIRouter, Depends, Request
from sqlalchemy.ext.asyncio import AsyncSession

from config.get_db import get_db
from module_admin.aspect.data_scope import GetDataScope
from module_admin.aspect.interface_auth import CheckUserInterfaceAuth
from module_admin.entity.vo.user_vo import CurrentUserModel
from module_admin.service.login_service import LoginService
from module_product.service.bg_product_price_service import BgProductPriceService
from module_product.entity.vo.bg_product_price_vo import BgProductPricePageModel, BgProductPriceModel
from utils.response_util import ResponseUtil

bgProductPriceController = APIRouter(prefix="/productPrice")


@bgProductPriceController.get('/list', dependencies=[Depends(CheckUserInterfaceAuth('product:price:query'))])
async def get_bg_product_price_list(
        request: Request,
        query_object: BgProductPricePageModel = Depends(),
        query_db: AsyncSession = Depends(get_db),
):
    """
    获取产品价格列表
    """
    bg_product_price_list = await BgProductPriceService.get_bg_product_price_list(
        query_db, query_object, None, True
    )
    return ResponseUtil.success(model_content=bg_product_price_list)


@bgProductPriceController.get('/{bg_product_price_id}', dependencies=[Depends(CheckUserInterfaceAuth('product:price:query'))])
async def get_bg_product_price_detail(
        request: Request,
        bg_product_price_id: int,
        query_db: AsyncSession = Depends(get_db)
):
    """
    获取产品价格详情
    """
    bg_product_price = await BgProductPriceService.get_bg_product_price_detail(query_db, bg_product_price_id)
    return ResponseUtil.success(data=bg_product_price)


@bgProductPriceController.get('/product/{product_id}', dependencies=[Depends(CheckUserInterfaceAuth('product:price:query'))])
async def get_bg_product_prices_by_product_id(
        request: Request,
        product_id: int,
        query_db: AsyncSession = Depends(get_db)
):
    """
    根据产品ID获取所有价格
    """
    prices = await BgProductPriceService.get_bg_product_prices_by_product_id(query_db, product_id)
    return ResponseUtil.success(data=prices)


@bgProductPriceController.post('/add', dependencies=[Depends(CheckUserInterfaceAuth('product:price:add'))])
async def add_bg_product_price(
        request: Request,
        bg_product_price: BgProductPriceModel,
        query_db: AsyncSession = Depends(get_db),
        current_user: CurrentUserModel = Depends(LoginService.get_current_user),
):
    """
    添加产品价格
    """
    bg_product_price.create_by = current_user.user.user_id
    bg_product_price.dept_id = current_user.user.dept_id
    bg_product_price = await BgProductPriceService.add_bg_product_price(query_db, bg_product_price)
    return ResponseUtil.success(data=bg_product_price)


@bgProductPriceController.put('/edit', dependencies=[Depends(CheckUserInterfaceAuth('product:price:edit'))])
async def edit_bg_product_price(
        request: Request,
        bg_product_price: BgProductPriceModel,
        query_db: AsyncSession = Depends(get_db)
):
    """
    编辑产品价格
    """
    await BgProductPriceService.edit_bg_product_price(query_db, bg_product_price)
    return ResponseUtil.success()


@bgProductPriceController.delete('/delete/{bg_product_price_id}', dependencies=[Depends(CheckUserInterfaceAuth('product:price:remove'))])
async def delete_bg_product_price(
        request: Request,
        bg_product_price_id: int,
        query_db: AsyncSession = Depends(get_db)
):
    """
    删除产品价格
    """
    result = await BgProductPriceService.delete_bg_product_price(query_db, bg_product_price_id)
    return ResponseUtil.success(data=result)
